#include <iostream>
#include <cstdlib>

#include <ctime>
#include <fstream>
#include "Vector.h"
using VECTOR::Vector;

int main2()
{
	srand(time(0));
	double direction;
	Vector step;
	Vector result(0.0, 0.0);
	unsigned long steps = 0;
	double target;
	double dstep;

	ofstream stream;
	stream.open("randwalk.txt");
	if (!stream.is_open())return -1;

	int n = 0;
	int max = 0;
	int min = 0;
	bool flag = true;
	double totals = 0.0;
	while (n < 3)
	{
		while (cin >> target)
		{
			cin >> dstep;
			stream << "Target Distance: " << target << ", Step Size: " << dstep << endl;
			while (result.magval() < target)
			{
				stream << steps << ": (x,y) = (" << result.xval() << ", " << result.yval() << ")" << endl;
				direction = rand() % 360;
				step.reset(dstep, direction, Vector::POL);
				result = result + step;
				steps++;
			}
			stream << steps << ": (x,y) = (" << result.xval() << ", " << result.yval() << ")" << endl;
			if (flag)
			{
				min = max = steps;
				flag = false;
			}
			if (steps > max)max = steps;
			if (steps < min)min = steps;
			totals += steps;
			stream << "After " << steps << " steps,the subject has the following location:\n";
			stream << result << endl;
			result.polar_mode();
			stream << "or\n" << result << endl;
			stream << "Average outward distance per step = " << result.magval() / steps << endl;
			steps = 0;
			result.reset(0.0, 0.0);
		}
		n++;
	}
	cout << "max:" << max << " min:" << min << " average:" << totals / n << endl;
	
}